package com.atguigu.mybatisgenerator.util;



import com.atguigu.mybatisgenerator.model.Page;
import com.github.pagehelper.PageInfo;


/**
 * 
 * 公用返回结果类
 */
public class ResponseResult {
	
	/**返回错误编码*/
	private int errcode;
	/**返回错误信息*/
	private String errmsg;
	/**返回结果*/
	private Object result;
	/**分页**/
	private Page page;
	
	public int getErrcode() {
		return errcode;
	}
	public void setErrcode(int errcode) {
		this.errcode = errcode;
	}
	public String getErrmsg() {
		return errmsg;
	}
	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}
	public Object getResult() {
		return result;
	}
	public void setResult(Object result) {
		this.result = result;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	@Override
	public String toString() {
		return "ResponseResult [errcode=" + errcode + ", errmsg=" + errmsg + ", result=" + result + "]";
	}
	
	public ResponseResult() {
		
	}
	
	public ResponseResult(int errcode, String errmsg, Object result) {
		super();
		this.errcode = errcode;
		this.errmsg = errmsg;
		this.result = result;
	}
	
	public ResponseResult(int errcode, String errmsg) {
		super();
		this.errcode = errcode;
		this.errmsg = errmsg;
	}
	public ResponseResult(int errcode, String errmsg, Object result, Page page){
		this.errcode = errcode;
		this.errmsg = errmsg;
		this.result = result;
		this.page = page;
	}

	/**处理成功返回 无返回内容*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult successResult(){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(),
								  ResultEnum.RESULT_SUCCESS.getValue()
								  );
	}

	/**
	 * 处理成功，返回提示错误
	 * @param msg
	 * @return
	 */
	public static com.atguigu.mybatisgenerator.util.ResponseResult successResult(String msg){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(), msg);
	}
	/**处理成功返回*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult successResult(Object obj){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(),
								  ResultEnum.RESULT_SUCCESS.getValue(),
								  obj);
	}
	/**处理成功返回对象**/
	public static com.atguigu.mybatisgenerator.util.ResponseResult successResult(String message, Object obj){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(),
				//ResultEnum.RESULT_SUCCESS.getValue(),
				message,
				obj);
	}
	/**处理成功分页对象**/
	public static com.atguigu.mybatisgenerator.util.ResponseResult successResult(String msg, PageInfo<?> pageInfo){
		Page page = new Page();
		page.setPages(pageInfo.getPages());
		page.setTotal(pageInfo.getTotal());
		page.setPageNum(pageInfo.getPageNum());
		page.setPageSize(pageInfo.getPageSize());
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(),
				ResultEnum.RESULT_SUCCESS.getValue(),
				pageInfo.getList(),page);
	}
	/**处理失败返回*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult errorResult(Object obj){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_ERROR.getCode(),
								  ResultEnum.RESULT_ERROR.getValue(),
								  obj);
	}
	/**处理失败加提示错误**/
	public static com.atguigu.mybatisgenerator.util.ResponseResult errorResult(String errmsg){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_ERROR.getCode(),
				errmsg);
	}
	/**处理失败返回  无返回内容*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult errorResult(){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.RESULT_ERROR.getCode(),
								  ResultEnum.RESULT_ERROR.getValue()
								  );
	}
	
	/**参数错误返回*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult paramsErrorResult(){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.PARAM_ERROR.getCode(),
								  ResultEnum.PARAM_ERROR.getValue()
								  );
	}
	/**参数错误返回*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult paramsErrorResult(String errmsg){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.PARAM_ERROR.getCode(),
				errmsg
		);
	}

	/**mq消息处理错误返回*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult sendErrorResult(){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.SEND_ERROR.getCode(),
				ResultEnum.SEND_ERROR.getValue()
				);
	}
	/**mq消息处理错误返回*/
	public static com.atguigu.mybatisgenerator.util.ResponseResult consumeErrorResult(){
		return new com.atguigu.mybatisgenerator.util.ResponseResult(ResultEnum.CONSUME_ERROR.getCode(),
				ResultEnum.CONSUME_ERROR.getValue()
				);
	}
}
